package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.KuCuiYvJing;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface KuCunYvJingMapper extends BaseMapper<KuCuiYvJing> {


    @Select("SELECT a.id,a.name,a.storenum,b.outnum FROM(\n" +
            "SELECT g.id,g.name,SUM(IFNULL(sl.number,0)) storenum FROM smbms_goods g, smbms_store_detail sl WHERE g.id=sl.good_id GROUP BY g.id,g.name\n" +
            ")a,(\n" +
            "SELECT ol.goods_id,SUM(ol.number) AS outnum FROM smbms_order_detail ol,smbms_order o WHERE o.id=ol.order_id AND o.type=2 AND ol.state=0 GROUP BY ol.goods_id\n" +
            ")b WHERE a.id=b.goods_id AND a.storenum<b.outnum\n")
    ///@ResultMap("OderRm")
    List<KuCuiYvJing> findAll(Page page, @Param("ew") Wrapper wrapper);
}
